import { fromJS } from 'immutable'
import { ADD_LIST, CHANGE_HOME_DATA } from './actionType'

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  articlePage: 0,
  showBackTop: false
})

export default (prevState = defaultState, action) => {
  switch (action.type) {
    case CHANGE_HOME_DATA: {
      const { articleList, topicList, recommendList } = action
      return prevState.merge({
        articleList: fromJS(articleList),
        topicList: fromJS(topicList),
        recommendList: fromJS(recommendList),
      })
    }
    case ADD_LIST: {
      const { list } = action
      return prevState.merge({
        articleList: prevState.get('articleList').concat(fromJS(list)),
        articlePage: action.nextPage,
      })
    }
    default:
      break
  }
  return prevState
}
